﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.ComponentModel;
using System.ComponentModel.Design;

namespace Booking_System.User_Controls
{
    /// <summary>
    /// Interaction logic for UCLogin.xaml
    /// </summary>
    public partial class UCLogin : UserControl
    {
        public static readonly RoutedEvent CreateLoginEvent =
            EventManager.RegisterRoutedEvent(
            "CreateLoginClick",
            RoutingStrategy.Direct,
            typeof(RoutedEventHandler),
            typeof(UCLogin)
        );

        public UCLogin()
        {
            InitializeComponent();
        }

        public event RoutedEventHandler CreateLoginClick
        {
            add { AddHandler(CreateLoginEvent, value); }
            remove { RemoveHandler(CreateLoginEvent, value); }
        }

        public String User
        {
            get
            {
                return this.TxtUser.Text;
            }
        }

        private String m_Pass = "";
        public String Pass
        {
            get
            {
                return System.Security.Cryptography.SHA1.Create().ComputeHash(System.Text.Encoding.UTF8.GetBytes(m_Pass)).ToString();
            }
        }

        private void BtnLogin_Click(object sender, RoutedEventArgs e)
        {
            RoutedEventArgs args = new RoutedEventArgs(CreateLoginEvent);
            RaiseEvent(args);
        }

        private void TxtUser_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
                BtnLogin_Click(sender, e);
        }

        private void TxtPass_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
                BtnLogin_Click(sender, e);
        }

        private void TxtPass_PasswordChanged(object sender, System.Windows.RoutedEventArgs e)
        {
            PasswordBox pb = sender as PasswordBox;
            m_Pass = pb.Password;
        }
    }
}
